<template>
  <div class="general-settings">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>通用设置</span>
        </div>
      </template>
      <el-form :model="form" label-width="120px">
        <el-form-item label="系统名称">
          <el-input v-model="form.systemName" />
        </el-form-item>
        <el-form-item label="系统Logo">
          <el-upload
            class="avatar-uploader"
            action="/api/upload"
            :show-file-list="false"
            :on-success="handleLogoSuccess"
          >
            <img v-if="form.logo" :src="form.logo" class="avatar" />
            <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
          </el-upload>
        </el-form-item>
        <el-form-item label="系统描述">
          <el-input v-model="form.description" type="textarea" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSave">保存设置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive } from 'vue';
import { Plus } from '@element-plus/icons-vue';
import { useGeneralStore } from '@/store/general';

export default defineComponent({
  name: 'GeneralSettings',
  components: {
    Plus
  },
  setup() {
    const generalStore = useGeneralStore();
    const form = reactive({
      systemName: '',
      logo: '',
      description: ''
    });

    const handleLogoSuccess = (response: any) => {
      form.logo = response.url;
    };

    const handleSave = async () => {
      await generalStore.updateSettings(form);
    };

    return {
      form,
      handleLogoSuccess,
      handleSave
    };
  }
});
</script>

<style lang="scss" scoped>
.general-settings {
  padding: 20px;

  .box-card {
    margin-bottom: 20px;
  }

  .avatar-uploader {
    :deep(.el-upload) {
      border: 1px dashed #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
      transition: var(--el-transition-duration-fast);

      &:hover {
        border-color: var(--el-color-primary);
      }
    }
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    text-align: center;
    line-height: 178px;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
}
</style> 